package com.aisile.shop.controller;

import com.aisile.entity.Result;
import com.aisile.pojogroup.Goods;
import com.aisile.sellergoods.service.GoodsService;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;



@RestController
@RequestMapping("goods")
public class GoodsController {

    @Reference
    GoodsService goodsService;

    @RequestMapping("save")
    public Result save(@RequestBody Goods goods){
        String sellerId = SecurityContextHolder.getContext().getAuthentication().getName();
        try {
            if (StringUtils.isEmpty(sellerId)){
                goodsService.save(goods);
                return new Result(true,"成功");
            }
            return new Result(false,"服务器出现异常");
        }catch (Exception e){
            return new Result(false,"服务器出现异常");
        }
    }
}
